<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 事件循环机制
        // 先执行同步 再执行异步 包括(微任务 宏任务) 先执行微任务  再执行宏任务
        console.log(0);
        let p1=new Promise((resolve,reject)=>{
            // 同步
            console.log('ysn');
            if(true){
                console.log('nihao');
                resolve('1');
            }else{
                reject('2');
            }
        })
        setTimeout(()=>{
            console.log('xx');
        },0)
        p1.then(data=>{
            console.log(data);
            console.log('ww');
        })
        p1.catch(err=>console.log(err));
        console.log('xx'); //0 xx ww
    </script>
</body>
</html>